package com.atguigu.sort;

import java.util.Arrays;

/**
 * description:
 * Created by 才睡醒 on 2021-06-22
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {101, 34, 119, 1,-1,90,123};


        for (int j = 0; j < arr.length-1; j++) {
            int miniIndex = j;
            int min = arr[j];

            for (int i = j + 1; i < arr.length; i++) {
                if (min > arr[i]) {
                    min = arr[i];
                    miniIndex = i;
                }
            }
            //将最小值放在arr【0】的位置
            arr[miniIndex] = arr[j];
            arr[j] = min;

        }
        System.out.println(Arrays.toString(arr));
    }
}




